package tomoto.draw;

import java.awt.Graphics2D;
import java.awt.font.TextLayout;
import java.awt.geom.Rectangle2D;

public class DrawUtil {
	@Deprecated
	private DrawUtil() {
	}

	/**
	 * Draws a string anchoring its center at the specified coords.
	 * 
	 * @param g2 graphics to draw
	 * @param x x coord
	 * @param y y coord
	 * @param s string to draw
	 */
	public static void drawCenteredString(Graphics2D g2, int x, int y, String s) {
		TextLayout t = new TextLayout(s, g2.getFont(), g2.getFontRenderContext());
		Rectangle2D r = t.getBounds();
		t.draw(g2, (float) (x - r.getCenterX()), (float) (y - r.getCenterY()));
	}

	/**
	 * Draws a grid.
	 * 
	 * @param g2 graphics to draw
	 * @param left x coord of the left
	 * @param top y coord of the top
	 * @param cellWidth width of a cell
	 * @param cellHeight height of a cell
	 * @param widthInCells grid width in number of cells 
	 * @param heightInCells grid height in number of cells
	 */
	public static void drawGrid(Graphics2D g2, int left, int top, int cellWidth,
			int cellHeight, int widthInCells, int heightInCells) {
		int heightInPixels = cellHeight * heightInCells;
		for (int i = 0; i <= widthInCells; i++) {
			int x = i * cellWidth;
			g2.drawLine(x, top, x, top + heightInPixels);
		}
		int widthInPixels = cellWidth * widthInCells;
		for (int i = 0; i <= heightInCells; i++) {
			int y = i * cellHeight;
			g2.drawLine(left, y, left + widthInPixels, y);
		}

	}

}
